package com.yzy.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzy.entity.User;
import com.yzy.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserService extends ServiceImpl<UserMapper, User> {

    @Resource
    private UserMapper userMapper;

    /**
     * @description 根据用户名和密码查询用户
     * @param user 前端封装的用户
     * @return com.yzy.entity.User
     * @author mgl
     * @date 2023/7/9 09:54
     */
    public User login(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",user.getUsername());
        wrapper.eq("password",user.getPassword());
        return userMapper.selectOne(wrapper);
    }

    public boolean changeAvatar(Integer userId, String avatarPath) {
        User user = new User();
        user.setAvatar(avatarPath);
        user.setId(userId);
        return updateById(user);
    }

    public String getAvatar(Integer userId) {
        User user = getById(userId);
        return user.getAvatar();
    }
}
